<?php

namespace app\common\model;

use think\Model;
use app\common\model\Mall;
class Goods extends Model
{
    //
    protected $autoWriteTimestamp =true;
    protected $type = [
        
        'create_time'  =>  'timestamp:Y/m/d H:i:s',
        'update_time'  =>  'timestamp:Y/m/d H:i:s',
    
    ];
    
    public function content(){
        return $this->hasOne('GoodsData','goods_id','id');
    }
    
    public function company(){
        return $this->hasOne('Company','user_id','user_id');
    }
    
    public function mall(){
        return $this->hasMany('Mall','goods_id','id')->field('price,id,stock');;
    }
    
    public function getMall(){
        $list = Mall::where('goods_id',$this->id)->order('price asc')->field('id,price,stock,sales')->select();
        return $list;
    }
    
    public function attr(){
        return $this->hasMany('GoodsAttr','goods_id','id');
    }
    public function spec(){
        return $this->hasManyThrough('MallSpec','Mall','goods_id','mall_id','id');
    }
    
    public function city(){
        return $this->hasOne('City','id','city_id');
    }
    
    public function fare(){
        return $this->hasOne('FareTmpl','id','fare_id');
    }
    
    public function getThumbAttr($url){
        return translateOssImg($url,500,500);
    }
    
    public function getPic1Attr($url){
        return translateOssImg($url,500,500);
    }
    public function getPic2Attr($url){
        return translateOssImg($url,500,500);
    }
    public function getPic3Attr($url){
        return translateOssImg($url,500,500);
    }
    public function getPic4Attr($url){
        return translateOssImg($url,500,500);
    }
    

    
    
    
}
